/* As the name indicates, this module is dedicated to manage lists of PCB. It is used to keep track of all processes in the system and to perform PID recycling. Such a list contains all the PCB used in the system sorted by PID. So, this module ensures a pcb_list is always sorted. */

#ifndef PCB_LIST_H
#define PCB_LIST_H

#include "null.h"
#include "types.h"
#include "pcb.h"
#include "error_codes.h"
#include "system_id.h"
#include "dynamic_memory.h"

/* type declaration */
typedef struct _pcb_list{
  PCB* pcb;
  struct _pcb_list* next;
}pcb_link, *pcb_list;


/* function declarations */

/* Looks for the first free pid using p_list, inserts pcb at the correct position after having assigned its pid and returns its pid in pid. Returns SUCCESS or OUT_OF_MEMORY. */
int32_t pcb_list_add(pcb_list* p_list, PCB* pcb, int32_t* pid);

/* removes pcb from p_list. Returns SUCCESS or FAILURE if pid is not in the list or if the free failed */
int32_t pcb_list_remove(pcb_list* p_list, PCB* pcb);

/* returns the number of elements in p_list */
int32_t pcb_list_count(pcb_list p_list);

/* returns an array containing all the PID in p_list and writes their number in length. It returns NULL if the system has run out of memory. */
int32_t* pcb_list_get_all_pid(pcb_list p_list, int32_t* length, int32_t owner);

#endif

